package api

import (
	"api-gatwary/until"
	"github.com/gin-gonic/gin"
	"net/http"
	"path/filepath"
)

func Upload(c *gin.Context) {
	file, m, err := c.Request.FormFile("image")
	if err != nil {
		return
	}
	upload, err := until.Upload(file, m)
	if err != nil {
		return
	}
	suffix := map[string]bool{
		".mp4":  true,
		".webp": true,
		".avi":  true,
	}
	ext := filepath.Ext(m.Filename)
	if suffix[ext] == false {
		c.JSON(http.StatusUnauthorized, gin.H{
			"code":    http.StatusUnauthorized,
			"Message": "文件格式不正确",
			"data":    false,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    http.StatusOK,
		"Message": "上传成功",
		"data":    upload,
	})
	return

}
